#include<iostream>
#include<vector>
using namespace std;
// OR57 手套
// https://www.nowcoder.com/practice/365d5722fff640a0b6684391153e58d8?tpId=182&tqId=34783&ru=/exam/oj

class Gloves {
public:
    int findMinimum(int n, vector<int> left, vector<int> right) 
    {
        int lout=0;
        int rout=0;
        int lmin=left[0];
        int rmin=right[0];
        int suml=0,sumr=0;
        for(int i=0;i<left.size();i++)
        {
            suml+=left[i];
            sumr+=right[i];
            if(lmin<left[i])
            {
                lmin=left[i];
            }
            if(rmin<right[i])
            {
                rmin=right[i];
            }
        }
        for(int i=0;i<left.size();i++)
        {
            if(left[i]==0&&right[i]!=0)
            {
                rout+=right[i];
                continue; 
            }
            if(left[i]!=0&&right[i]==0)
            {
                lout+=left[i];
                continue;
            }
            if(left[i]==0&&right[i]==0)
            {
                continue;
            }
            if(left[i]<lmin)
            {
                lmin=left[i];
            }
            if(right[i]<rmin)
            {
                rmin=right[i];
            }
        }
        suml=suml-lmin+1;
        suml=suml+rout+1;
        sumr=sumr-rmin+1;
        sumr=sumr+lout+1;
        return suml<sumr?suml:sumr;
    }
};
